package com.yc.sole.code.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import lombok.extern.slf4j.Slf4j;

/**
 * 代码生成器
 *
 * @author yizuomin
 * @date 2022/11/22 19:28
 **/
@Slf4j
public class RunGenerator {

    public static final String PACKAGE_PREFIX = "com.yc.sole.";

    public static void main(String[] args) {
        String moduleName = "system";
        ConfigProperty config = new ConfigProperty();
        config.setAuthor("yizuomin");
        config.setExceptionName("BaseException");
        //config.setOutFilePath("/Users/yizuomin/dev/gitee/zooming-platform/zooming-repository/zooming-tenant-repository/src/main/java/");
        config.setOutFilePath("/Users/yizuomin/zooming_code");// 输出路径

        config.setTables(new String[]{
                "sys_biz_log"
        }); //表名
        config.setTablePrefix(new String[]{"sys_"});
        // 包路径配置
        config.setControllerPackagePath(PACKAGE_PREFIX + moduleName + ".controller");
        config.setServicePackagePath(PACKAGE_PREFIX + moduleName + ".service");
        config.setServiceImplPackagePath(PACKAGE_PREFIX + moduleName + ".service.impl");
        config.setRepositoryPackagePath(PACKAGE_PREFIX + moduleName + ".repository");
        config.setBizPackagePath(PACKAGE_PREFIX + moduleName + ".biz");
        config.setMapperPackagePath(PACKAGE_PREFIX + moduleName + ".mapper");
        config.setXmlPackagePath(PACKAGE_PREFIX + moduleName + ".mapping");
        config.setEntityPackagePath(PACKAGE_PREFIX + moduleName + ".entity");
        config.setDtoPackagePath(PACKAGE_PREFIX + moduleName + ".dto");
        config.setReqPackagePath(PACKAGE_PREFIX + moduleName + ".request");
        config.setQueryReqPackagePath(PACKAGE_PREFIX + moduleName + ".request");
        config.setRespPackagePath(PACKAGE_PREFIX + moduleName + ".response");

        // 模板配置
        config.setControllerTemplateLocation("/templates/controller.java.vm");
        config.setEntityTemplateLocation("/templates/entity.java.vm"); // 实体类生成通过模板存在问题，直接按默认的生成即可
        config.setMapperTemplateLocation("/templates/mapper.java.vm");
        config.setBizTemplateLocation("/templates/biz.java.vm");
        config.setServiceTemplateLocation("/templates/service.java.vm");
        config.setServiceImplTemplateLocation("/templates/serviceImpl.java.vm");
        config.setRepositoryTemplateLocation("/templates/repository.java.vm");
        config.setDtoTemplateLocation("/templates/dto.java.vm");
        config.setReqTemplateLocation("/templates/req.java.vm");
        config.setQueryReqTemplateLocation("/templates/queryReq.java.vm");
        config.setRespTemplateLocation("/templates/resp.java.vm");

        // 数据库配置

        config.setDbUrl("jdbc:mysql://localhost:3306/yc_sole_basic");
        config.setDbDriverName("com.mysql.cj.jdbc.Driver");
        config.setDbUsername("root");
        config.setDbPassword("123456");
        config.setDbType(DbType.MYSQL);
        config.setDbTypeConvert(new MySqlTypeConvert());
        config.setModuleName(moduleName);

        new MyBatisPlusGenerator(config).run();
    }


}
